<?php

	// TITLE: Home_owner_income AUTO MODEL
	// FILE: scaffolding/model/home_owner_income.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createHomeOwnerIncome = function($con, $homeOwnerIncome) {
		$sql = 'INSERT INTO home_owner_income (id, home_owner_id, gross, overtime, commission, child_support, social_security, disability, pension, unemployment) VALUES (';
		$sql .= $home_owner_income->getId() . ', ';
		$sql .= $home_owner_income->getHomeOwnerId() . ', ';
		$sql .= $home_owner_income->getGross() . ', ';
		$sql .= $home_owner_income->getOvertime() . ', ';
		$sql .= $home_owner_income->getCommission() . ', ';
		$sql .= $home_owner_income->getChildSupport() . ', ';
		$sql .= $home_owner_income->getSocialSecurity() . ', ';
		$sql .= $home_owner_income->getDisability() . ', ';
		$sql .= $home_owner_income->getPension() . ', ';
		$sql .= $home_owner_income->getUnemployment() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readHomeOwnerIncome = function($con, $id) {
		$sql = 'SELECT * FROM home_owner_income WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$homeOwnerIncome = new HomeOwnerIncome();
			$homeOwnerIncome->setId(result[0]);
			$homeOwnerIncome->setHomeOwnerId($dbio->select($readHomeOwner(result[1])));
			$homeOwnerIncome->setGross(result[2]);
			$homeOwnerIncome->setOvertime(result[3]);
			$homeOwnerIncome->setCommission(result[4]);
			$homeOwnerIncome->setChildSupport(result[5]);
			$homeOwnerIncome->setSocialSecurity(result[6]);
			$homeOwnerIncome->setDisability(result[7]);
			$homeOwnerIncome->setPension(result[8]);
			$homeOwnerIncome->setUnemployment(result[9]);
		} else {
			$homeOwnerIncome = false;
		}
		return $homeOwnerIncome;
	};

	$updateHomeOwnerIncome = function($con, $homeOwnerIncome) {
		$sql = 'UPDATE home_owner_income SET ';
		$sql .= 'id = ' . $home_owner_income->getId() . ', ';
		$sql .= 'home_owner_id = ' . $home_owner_income->getHomeOwnerId() . ', ';
		$sql .= 'gross = ' . $home_owner_income->getGross() . ', ';
		$sql .= 'overtime = ' . $home_owner_income->getOvertime() . ', ';
		$sql .= 'commission = ' . $home_owner_income->getCommission() . ', ';
		$sql .= 'child_support = ' . $home_owner_income->getChildSupport() . ', ';
		$sql .= 'social_security = ' . $home_owner_income->getSocialSecurity() . ', ';
		$sql .= 'disability = ' . $home_owner_income->getDisability() . ', ';
		$sql .= 'pension = ' . $home_owner_income->getPension() . ', ';
		$sql .= 'unemployment = ' . $home_owner_income->getUnemployment() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteHomeOwnerIncome = function($con, $id) {
		$sql = 'DELETE FROM home_owner_income WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listHomeOwnerIncome = function($con) {
		$sql = 'SELECT * FROM home_owner_income';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$homeOwnerIncomes = array();
			while ($result = mysqli_fetch_array($results)) {
				$homeOwnerIncome = new HomeOwnerIncome();
				$homeOwnerIncome->setId(result[0]);
				$homeOwnerIncome->setHomeOwnerId($dbio->select($readHomeOwner(result[1])));
				$homeOwnerIncome->setGross(result[2]);
				$homeOwnerIncome->setOvertime(result[3]);
				$homeOwnerIncome->setCommission(result[4]);
				$homeOwnerIncome->setChildSupport(result[5]);
				$homeOwnerIncome->setSocialSecurity(result[6]);
				$homeOwnerIncome->setDisability(result[7]);
				$homeOwnerIncome->setPension(result[8]);
				$homeOwnerIncome->setUnemployment(result[9]);
				$homeOwnerIncomes[] = homeOwnerIncome;
			}// end while
		} else {
			$homeOwnerIncomes = false;
		}
		return $homeOwnerIncomes;
	};

